import { WeElement, define } from 'omi'

import './index.css'

define("time-picker", class extends WeElement{
  
  data={
    date: "",
    nowDate: ""
  }

  install(){
    let date = new Date();
    let dateStr = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
    console.log(dateStr);
    this.data.nowDate = dateStr;
  }

//选择预约时间
  bindDateChange=(e)=>{
    console.log(e)
    // console.log(this)
    if(e.detail.value == "2019-04-02"){
      wx.showToast({
        title: '该时间未开放...',
        icon: 'none'
      })
      return;
    }else{
      console.log(e.detail.value);
      this.data.date = e.detail.value;
      this.fire('choosedate', {
        date: this.data.date
      })
      this.update();
    }
  }

  render(){
    const {date} = this.data;
    return(
      <view class="time_picker">
        <picker
          mode="date"
          value={date}
          start={nowDate}
          end="2100-01-01"
          bindchange={bindDateChange}
          disabled={false}
        >
          <view>
          {
              date ? date : '请选择您的取票时间 '
          }
          </view>
        </picker>
      </view>
    )
  }
})